package com.software.aperture.service;

import com.software.aperture.bean.Post;
import com.software.aperture.repository.PostRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
public class PostService {
    @Resource
    PostRepository postRepository;

    public List<Post> getAllPosts(){
        return postRepository.findAll();
    }

    public Optional<Post> getPostById(Integer postId){
        return postRepository.findById(postId);
    }

    public void addPost(Post post){
        postRepository.save(post);
    }

    public void deletePostById(Integer postId){
        postRepository.deleteById(postId);
    }

    public void updatePost(Post post){
        postRepository.save(post);
    }
}
